/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */
package com.shishuo.cms.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.shishuo.cms.Directory;
import com.shishuo.cms.constant.FolderConstant.status;
import com.shishuo.cms.entity.Product;
import com.shishuo.cms.entity.vo.FolderVo;
import com.shishuo.cms.service.ProductService;

@Controller
@RequestMapping("/product")
public class ProductAction extends BaseAction {

	@Autowired
	private ProductService productService;
	final String path="/template/blog/"; 	//返回路劲
	/**
	 * 产品详情
	 * 
	 * @param ename
	 * @param pageNum
	 * @param modelMap
	 * @return
	 */
	@RequestMapping(value = "/{productId}.htm", method = RequestMethod.GET)
	public String fourthFolder(@PathVariable long productId,
			ModelMap modelMap) {
		try {
			String suffix="productDetail";//返回路劲后缀
			List<FolderVo> folderVos=new ArrayList<>();
			List<FolderVo> childFolderVos=folderService.getFolderListByFatherId(
					Directory.PRODUCT.getType(), status.display);
			Product product=productService.getProductById(productId);
			if (childFolderVos.size()==0) {
				folderVos.add(folderService.getFolderById(Directory.PRODUCT.getType()));
			}else {
				folderVos.addAll(childFolderVos);
			}
			modelMap.put("folderAll", folderVos);
			modelMap.put("productFolderId", product.getFolderId());
			modelMap.put("showFolder", Directory.PRODUCT.getType());
			modelMap.put("g_folderId", Directory.PRODUCT.getType());
			modelMap.put("product", product);
			return path+suffix;
		} catch (Exception e) {
			modelMap.addAttribute("g_folderId", folderService.getFolderByOrderAndFatherId(0).getFolderId());
			logger.fatal(e.getMessage());
			return themeService.get404();
		}
	}
}
